package xin.codedream.codelog.service.impl;

import org.springframework.stereotype.Service;
import xin.codedream.codelog.dao.UserDao;
import xin.codedream.codelog.model.entity.User;
import xin.codedream.codelog.service.UserService;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 用户业务逻辑接口实现
 *
 * @author NGLSL
 * @date 2018/8/4
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;

    @Override
    public User userLoginByNameAndPass(String userName, String userPass) {
        return userDao.selectUserByUserNameAndUserPass(userName, userPass);
    }

    @Override
    public User findUser() {
        return userDao.selectUser();
    }

    @Override
    public void updateLoginError(User user) {
        int count = user.getLoginError() == null ? 0 : user.getLoginError() + 1;
        userDao.updateLoginError(user.getUserId(), count);
    }

    @Override
    public void updateLoginStatus(User user, Integer enable) {
        userDao.updateLoginStatus(user.getUserId(), enable);
    }

    @Override
    public void updateLastLoginTime(User user, Date date) {
        userDao.updateLastLoginTime(user.getUserId(), date);
    }
}
